﻿using Common;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace UIComponentSprite.Grid
{
    /// <summary>
    /// 地图网格
    /// </summary>
    public class GridUnitSprite : UserControlledSprite
    {
        private static Texture2D _imageStatic;//图片对象单例
        private GridTypeEnum _currentGridType = GridTypeEnum.None; //当前网格

        /// <summary>
        /// 将要显示的网格类型
        /// </summary>
        public GridTypeEnum WillDisplayType { get; set; }

        public GridUnitSprite()
        {

        }

        public override void Draw(GameTime gameTime)
        {
            if (!Showing)
                return;
            SpriteBatch.Draw(_imageStatic, DrawPosition, Color.White);
        }

        public override void Update(GameTime gameTime)
        {
            if (!Showing)
                return;
            LoadPic();
        }

        protected override void LoadPic()
        {
            if (this._currentGridType != this.WillDisplayType)
            {
                switch (this.WillDisplayType)
                {
                    case GridTypeEnum.Wangge:
                        this.ImgUrl = @"Images\grid\Wangge";
                        break;
                }
               _imageStatic = Game.Content.Load<Texture2D>(this.ImgUrl);
                this._currentGridType = this.WillDisplayType;
            }


        }
    }

}
